<?php

if ( !defined( 'BASEPATH' ) ) exit( 'No direct script access allowed' );

/**
 * 搜索模块
 */
class Search extends MY_Controller
{
    //默认合法的控制器
    private $_validController = array(
        'rent',
        'sell',
    );
    
    /**
     * 金额范围
     * @var array
     */
    private $_priceRange = array(
        array('id' => '0-700', 'name' => '700元以下'),
        array('id' => '700-1500', 'name' => '700-1500元'),
        array('id' => '1500-2000', 'name' => '1500-2000元'),
        array('id' => '2000-2500', 'name' => '2000-2500元'),
        array('id' => '2500-3000', 'name' => '2500-3000元'),
        array('id' => '3000-3500', 'name' => '3000-3500元'),
        array('id' => '3500-4000', 'name' => '3500-4000元'),
        array('id' => '4000-4500', 'name' => '4500-5000元'),
        array('id' => '4500-max', 'name' => '4500以上'),
    );
    
    /**
     * 获取所有区域数据
     * @return array
     */
    public function getZone()
    {
        return $this->model_common_getZoneData();
    }
    
    /**
     * 获取所有厅室数据
     * @return array
     */
    public function getRoom()
    {
        return $this->model_common_getRoomData();
    }
    
    /**
     * 金额范围
     */
    public function getPriceRange()
    {
        return $this->_priceRange;
    }
    
    public function index( $keyword = '' )
    {
        $data = array(
            'current' => $this->getCurrentController(),
            'zone' => $this->getZone(),
            'room' => $this->getRoom(),
            'priceRange' => $this->getPriceRange(),
            'keyword' => $keyword,
        );
        $this->load->view( 'search', $data );
    }
    
    /**
     * 获取当前控制器
     * @return string
     */
    private function getCurrentController()
    {
        $cur = $this->uri->segment(1);
        if ( empty( $cur ) || !in_array( $cur, $this->_validController ) ) return 'rent';
        return $cur;
    }

}